/**
 * @author: Miss.杨
 * @date: 2025年3月08日 16:01:57
 * @description: 
 */
package com.sheepone.monitor.audit.server;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.sheepone.monitor.audit.core.entities.ActionSelectableInfo;
import com.sheepone.monitor.audit.core.enums.ActionEnum;

/**
 * @author: Miss.杨
 * @date: 2025年3月08日 16:01:57
 * @description:
 */
public class ActionRouter {
    private final HashMap<ActionEnum, ActionHandler<?>> actionHandlers = new HashMap<>();

    public void register(ActionEnum action, ActionHandler<?> handler){
        handler.init();
        actionHandlers.put(action, handler);
    }

    public ActionHandler<?> route(String action) {
        return actionHandlers.get(ActionEnum.getEnum(action));
    }

    public List<ActionSelectableInfo> getActionSelectableList() {
        ArrayList<ActionSelectableInfo> list = new ArrayList<>(actionHandlers.size());
        for (ActionEnum action : actionHandlers.keySet()) {
            ActionSelectableInfo info = new ActionSelectableInfo();
            info.setName(action.getName());
            info.setValue(action.getAction());
            list.add(info);
        }
        return list;
    }

}
